package com.rs.game.player.dialogues;

import java.util.Random;

import com.rs.game.World;
import com.rs.utils.Utils;

public class DicingMaster extends Dialogue{

	private int npcId;

	@Override
	public void start() {
		npcId = (Integer) parameters[0];
		sendNPCDialogue(npcId, 9827, "Hello, you can bet 5M to win the Gamble Item of the Week. You need to roll over 95 in order to win. The current Gamble Item of the Week is: Golden Scythe." +
				"So, would you like to play?");
	}

	@Override
	public void run(int interfaceId, int componentId) {
		if (stage == -1) {
			stage = 0;
			sendOptionsDialogue("Select an Option", "Yes", "No");
		} else if (stage == 0) {
			if (componentId == OPTION_1) {
				Random rand = new Random();
				int roll = rand.nextInt(100) + 1;
				if (player.getInventory().containsItem(995, 5000000)) {
					player.getInventory().deleteItem(995, 5000000);
					if (roll >= 95) {
						sendNPCDialogue(npcId, 9827, "You have rolled <col=db3535>"+("" + roll)+"");
						player.getInventory().addItem(22321, 1);
						World.sendWorldMessage("<col=26E061> " + Utils.formatPlayerNameForDisplay(player.getDisplayName()) + " has just received the " + "<col=32CED9>" +"Golden Scythe"+ "</col>" + "<col=26E061>" + " from the Gambler!", false);
						stage = 1;
					} else {
						sendNPCDialogue(npcId, 9827, "You have rolled <col=db3535>"+("" + roll)+"");
						stage = 1;
					}
				} else {
					player.getPackets().sendGameMessage("You need 5M in order to participate.");
					end();
				}
			} else if (componentId == OPTION_2) {
				end();
			}
		} else if (stage == 1) {
			end();
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		
	}
}